/*
 * Copyright (c) 2024-2025.  little3201.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *       https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.leafage.exploiter.constants;

/**
 * 数据库类型映射到Java类型、组件名和TypeScript类型
 *
 * @author wq li
 */
public enum FieldTypeEnum {

    INT2("int2", "Short", "input-number", "number"),
    INT4("int4", "Integer", "input-number", "number"),
    INT8("int8", "Long", "select", "number"),
    FLOAT4("float4", "Float", "input-number", "number"),
    FLOAT8("float8", "Double", "input-number", "number"),
    NUMERIC("numeric", "BigDecimal", "input-number", "number"),
    BOOL("bool", "Boolean", "switch", "boolean"),
    VARCHAR("varchar", "String", "input", "string"),
    TEXT("text", "String", "input", "string"),
    DATE("date", "LocalDate", "date-picker", "Date"),
    TIME("time", "LocalTime", "time-picker", "Date"),
    TIMESTAMP("timestamp", "LocalDateTime", "date-picker", "Date"),
    JSON("json", "String", "input", "string");


    private final String dbType;
    private final String javaType;
    private final String formType;
    private final String tsType;

    FieldTypeEnum(String dbType, String javaType, String formType, String tsType) {
        this.dbType = dbType;
        this.javaType = javaType;
        this.formType = formType;
        this.tsType = tsType;
    }

    public static FieldTypeEnum getByDbType(String dbType) {
        for (FieldTypeEnum mapping : values()) {
            if (mapping.dbType.equalsIgnoreCase(dbType)) {
                return mapping;
            }
        }
        return null;
    }

    public String getJavaType() {
        return javaType;
    }

    public String getFormType() {
        return formType;
    }

    public String getTsType() {
        return tsType;
    }

}
